package dados;
import negocio.CorBean;

import org.hibernate.Session;


import java.util.List;

public class CorDAO {

	public void armazenarCor(String codigo,String descricao) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
		CorBean c= new CorBean();
		c.setCodigo(codigo);
		c.setDescricao(descricao);
		
		session.save(c);
		session.getTransaction().commit();
		}
	
	public void editarCor(CorBean c,String codigo,String descricao){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		c.setCodigo(codigo);
		c.setDescricao(descricao);
		session.update(c);
		session.getTransaction().commit();	
	}
	public List listar(){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List result = session.createQuery("from CorBean").list();
		session.getTransaction().commit();
		return  result;
	}
	public void excluirCor(CorBean c){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.delete(c);
		session.getTransaction().commit();	
	}
	
}
